﻿using DimensionsHelper.LanguageService.Syntax;

namespace DimensionsHelper.LanguageService.Symbols;

public class MetadataSuffixSymbol(IDeclaration declaration)
    : MetadataSymbol(SymbolKinds.MetadataSuffix, declaration)
{
    private DomainSymbolTable? _domainSymbolTable;

    public SyntaxNode? Value { get; protected set; }


    /// <summary>
    ///     后缀符号中，有一些包含语句块（codes、helperFields等），
    ///     使用此方法将符号添加到成员表中。
    /// </summary>
    public bool DeclareNamedMember(ISymbol symbol)
    {
        _domainSymbolTable ??= new DomainSymbolTable(this);
        return _domainSymbolTable.DeclareSymbol(symbol);
    }


    public override bool Redeclare(ISymbol symbol)
    {
        if (symbol is not MetadataSuffixSymbol suffix ||
            !suffix.Name.Equals(Name, StringComparison.OrdinalIgnoreCase))
        {
            return false;
        }

        Value = suffix.Value;
        return true;
    }
}